package utils

import (
	"roc/wechat/utils/redis"
	"time"
)

type RedisClient interface {
	Get(key string) interface{}
	GetStr(key string) string
	GetInt64(key string) (int64, error)
	GetUInt64(key string) (uint64, error)
	RedisBytes(key string) (data []byte, err error)
	RedisString(key string) (data string, err error)
	RedisInt(key string) (data int, err error)
	Put(key string, val interface{}, timeout time.Duration) error
	SetNX(key string, val interface{}, timeout time.Duration) bool
	Delete(key string) error
	IsExist(key string) bool
	LPush(key string, val interface{}) error
	Brpop(key string, callback func([]byte))
	GetRedisTTL(key string) time.Duration
	Incrby(key string, num int) (interface{}, error)
	Do(commandName string, args ...interface{}) (reply interface{}, err error)
}

func InitRedis(redisType string, conf string) (redisClient RedisClient, err error) {
	switch redisType {
	case "cluster": // 集群
		redisClient, err = redis.InitClusterRedis(conf)
	default: // 默认走单机
		redisClient, err = redis.InitStandaloneRedis(conf)
	}

	return
}

// redis没有key的错误
const RedisNoKeyErr = "redis: nil"

//const redisNoKeyErr = redis2.Error(redis2.Nil)
